import java.util.Calendar;

public class OnlyDate {
    private int year;
    private int month;
    private int day;

    public OnlyDate() {
        this.year = Calendar.getInstance().get(Calendar.YEAR);
        this.month = Calendar.getInstance().get(Calendar.MONTH) + 1;
        this.day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
    }

    public OnlyDate(long longFormatDate) {
        this.day = (int) (longFormatDate % 100);
        longFormatDate = (longFormatDate - longFormatDate % 100) / 100;
        this.month = (int) (longFormatDate % 100);
        longFormatDate = (longFormatDate - longFormatDate % 100) / 100;
        this.year = (int) longFormatDate;
    }

    static long getDate() {
        int year = Calendar.getInstance().get(Calendar.YEAR);
        int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
        int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
        return day + month * 100 + year * 10000L;
    }

    static long formatDate(int year, int month, int day) {
        return day + month * 100L + year * 10000L;
    }

    private int getYear() {
        return year;
    }

    private int getMonth() {
        return month;
    }

    private int getDay() {
        return day;
    }

    public boolean isBiggerThan(OnlyDate date) {
        if (this.year > date.getYear()) {
            return true;
        }
        if (this.month > date.getMonth()) {
            return true;
        }
        return this.day > date.getDay();
    }

    public boolean isBiggerThan(long aDate) {
        OnlyDate date = new OnlyDate(aDate);
        return this.isBiggerThan(date);
    }

    public boolean isBiggerOrEqualThan(OnlyDate date) {
        if (this.year >= date.getYear()) {
            return true;
        }
        if (this.month >= date.getMonth()) {
            return true;
        }
        return this.day >= date.getDay();
    }

    public boolean isBiggerOrEqualThan(long aDate) {
        OnlyDate date = new OnlyDate(aDate);
        return this.isBiggerOrEqualThan(date);
    }

    private int getMonthType() {
        return switch (this.month) {
            case 2 -> 2;
            case 4, 6, 9, 11 -> 1;
            default -> 0;
        };
    }

    private void addDayOnce() {
        int monthType = getMonthType();
        int yearType = this.year % 4;

        if ((this.day == 31 && monthType == 0) || (this.day == 30 && monthType == 1) || (monthType == 2 && ((yearType != 0 && this.day == 28) || (yearType == 0 && this.day == 29)))) {
            this.day = 1;
            this.month += 1;
        } else {
            this.day += 1;
        }

        if (this.month > 12) {
            this.month = 1;
            this.year += 1;
        }
    }

    public void addDays(int days) {
        for (int i = 0; i < days; ++i) {
            this.addDayOnce();
        }
    }

    public long getFormatDate() {
        return this.day + this.month * 100L + this.year * 10000L;
    }
}
